package com.taobao.action.ui;

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.MouseListener;
import org.eclipse.swt.events.MouseTrackListener;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Cursor;
import org.eclipse.swt.widgets.Label;

import com.swtdesigner.SWTResourceManager;
import com.taobao.action.CommonAction;
import com.taobao.ui.widget.CommonWidget;

public class LabelCursorAction implements MouseListener, MouseTrackListener{

    private CommonAction action;
    
    private CommonWidget commonWidget;
    
    private Color oldBgColor;
    
    public LabelCursorAction(CommonAction action, CommonWidget commonWidget) {
        this.action = action;
        this.commonWidget = commonWidget;
    }

    @Override
    public void mouseDoubleClick(MouseEvent e) {
    }

    @Override
    public void mouseDown(MouseEvent e) {
    }

    @Override
    public void mouseUp(MouseEvent e) {
        action.doAction(commonWidget);
    }

    

    @Override
    public void mouseEnter(MouseEvent e) {
        Label label = (Label) e.getSource();
        oldBgColor = label.getBackground();
        label.setCursor(new Cursor(null, SWT.CURSOR_HAND));
        label.setBackground(SWTResourceManager.getColor(SWT.COLOR_BLUE));
        label.setForeground(SWTResourceManager.getColor(SWT.COLOR_WHITE));
    }

    @Override
    public void mouseExit(MouseEvent e) {
        Label label = (Label) e.getSource();
        label.setForeground(SWTResourceManager.getColor(SWT.COLOR_BLUE));
        label.setBackground(oldBgColor);        
    }

    @Override
    public void mouseHover(MouseEvent e) {
    }

}
